package org.hot100_2;

public class leetcode42 {
    public int trap (int [] height){

        int sum =0;

        int n = height.length;

        for (int i = 1; i < n-1; i++) {
            int max_left = 0;
            int max_right =0;

            for (int j = 0; j < i; j++) {
                if (height[j]>max_left){
                    max_left=height[j];
                }
            }

            for (int j = i+1; j < n; j++) {
                if (height[j]>max_right){
                    max_right=height[j];
                }
            }

            int min = Math.min(max_left, max_right);

            if (min>height[i]){
                sum=sum+(min-height[i]);
            }
        }

        return sum;
    }

}
